﻿//=====================================================
// Copyright © 2017-2018 xuxuzhaozhao
// All rights reserved
// GUID: 54d29808-751f-432c-a25a-d4931592efa3
// CLR版本: 4.0.30319.42000
// 命名空间名称: xuxuzhaozhao.Blog.App_Start
// 文件名: XuExceptionAttribute
// 当前系统时间: 2017/11/8 10:33:27
// 当前登录用户名: xuxuzhaozhao
//======================================================

using System.Net;
using System.Net.Http;
using System.Web.Http.Filters;

namespace xuxuzhaozhao.Blog.XuException
{
    public class XuExceptionAttribute : ExceptionFilterAttribute
    {
        /// <inheritdoc />
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var ex = actionExecutedContext.Exception;
            if (ex is XuException)
            {
                var oResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                oResponse.Content = new StringContent(ex.Message);
                oResponse.ReasonPhrase = "Oops! xuxuzhaozhao Find Error.";
                actionExecutedContext.Response = oResponse;
            }
            else
            {
                var oResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                oResponse.Content = new StringContent(ex.Message);
                oResponse.ReasonPhrase = "Oops! xuxuzhaozhao Find Error.";
                actionExecutedContext.Response = oResponse;
            }
            base.OnException(actionExecutedContext);
        }
    }
}